﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace Election.BanToChucBinhBau
{
	public partial class Form_BanTCBB_UploadImg : Form
	{
		private string maucv;

		public Form_BanTCBB_UploadImg(string maucv)
		{
			InitializeComponent();
			this.maucv = maucv;
		}

		private void path_event(object sender, EventArgs e)
		{
			if (File.Exists(path.Text))
				img.Image = Image.FromFile(path.Text);
			else
				img.Image = null;
		}

		private void Form_BanTCBB_UploadImg_Load(object sender, EventArgs e)
		{
			ucv.Text = maucv;
			path.LostFocus += new EventHandler(path_event);
		}

		private void button1_Click(object sender, EventArgs e)
		{
			OpenFileDialog openFileDialog1 = new OpenFileDialog();
			openFileDialog1.InitialDirectory = "Desktop";
			openFileDialog1.Filter = "JPG files (*.jpg)|*.jpg|PNG files (*.png)|*.png";
			openFileDialog1.FilterIndex = 1;
			openFileDialog1.RestoreDirectory = true;
			openFileDialog1.Multiselect = false;
			if (openFileDialog1.ShowDialog() == DialogResult.OK)
			{
				try
				{
					if ((openFileDialog1.OpenFile()) != null)
					{
						path.Text = openFileDialog1.FileName;
						img.Image = Image.FromFile(path.Text);
					}
				}
				catch (Exception ex)
				{
					MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
				}
			}
		}

		private void button2_Click(object sender, EventArgs e)
		{
			if (File.Exists(path.Text))
			{
				File.Copy(path.Text, orcl.imagePath + maucv + ".png", true);
				MessageBox.Show("Upload ảnh thành công");
				this.Close();
			}
			else
				MessageBox.Show("File không tồn tại");
		}
	}
}
